package com.easybuilder.core.rbac.controller;

import com.easybuilder.common.base.controller.BaseController;
import com.easybuilder.common.base.entity.PageQueryWrapper;
import com.easybuilder.common.base.entity.PageResultWrapper;
import com.easybuilder.core.rbac.dto.SysUserDTO;
import com.easybuilder.core.rbac.entity.SysUser;
import com.easybuilder.core.rbac.service.SysUserService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ZXS
 * @version 1.0
 * @description 类
 * @date 2021-5-25 22:39
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController extends BaseController {
    @Resource
    private SysUserService sysUserService;
    /**
     * @Author zhangxingshuai
     * @Description //TODO 查询人员列表
     * @Date 9:41 2021/8/23
     * @Param []
     * @return com.easybuilder.common.base.controller.BaseController.Result
     **/
    @PostMapping("/page")
    public Result page(@RequestBody PageQueryWrapper<SysUser> queryWrapper) {

        PageResultWrapper<SysUser> page = sysUserService.page(queryWrapper);
        return OK(page);
    }

    @PostMapping("/insert")
    public Result insert(SysUser sysUser) {
        sysUserService.insert(sysUser);
        return OK(sysUser);
    }

    @PostMapping("/save")
    public Result save(@RequestBody SysUser sysUser) {
        if (sysUser == null) {
            return Error(HttpStatus.BAD_REQUEST, "参数异常");
        }
        sysUserService.save(sysUser);
        return OK("保存成功");
    }


    @GetMapping("/info")
    public Result<?> getCurrentUserInfo() {
        SysUserDTO sysUserDTO = sysUserService.getCurrentUserInfo();
        return OK(sysUserDTO);
    }

    @GetMapping("/{id}")
    public Result<?> getUserById(@PathVariable(name = "id", required = true) Long id) {
        SysUser user = sysUserService.getUserById(id);
        return OK(user);
    }

    @DeleteMapping("/{id}")
    public Result<?> deleteById(@PathVariable(name = "id", required = true) Long id) {
        sysUserService.deleteById(id);
        return OK("删除成功");
    }
}
